<template>
	<div class="layout-pd">
		<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
			<el-table-column prop="hid" label="id" width="300" />
			<el-table-column prop="name" label="作业名称"  width="300"></el-table-column>
			<!-- <el-table-column prop="roleSign" label="角色标识" show-overflow-tooltip></el-table-column>
				<el-table-column prop="sort" label="排序" show-overflow-tooltip></el-table-column> -->

			<!-- <el-table-column prop="describe" label="角色描述" show-overflow-tooltip></el-table-column> -->
			<el-table-column prop="endtime" :formatter="getLocalTime" label="截止时间"  width="400"></el-table-column>
		
			<el-table-column label="操作"  width="300">
				<template #default="scope">
					<el-button size="small" text type="primary" @click="Jump(scope)">查看</el-button>
					<!-- <el-button :disabled="scope.row.roleName === '超级管理员'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>  -->
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup lang="ts" name="funCropper">
import { storeToRefs } from 'pinia';
import { useUserInfo } from '/@/stores/userInfo';
import { onMounted, reactive, ref } from 'vue';
import { bind } from '/@/api/bindfiles/index';
import router from '/@/router';
import { Session } from '/@/utils/storage';
import { NextLoading } from '/@/utils/loading';



// 定义变量内容
const storesUserInfo = useUserInfo();
const { userInfos } = storeToRefs(storesUserInfo);
const userAuth = ref('');

// 定义变量内容
const state = reactive<SysRoleState>({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			hids: [],
			search: '',
			pageNum: 1,
			pageSize: 10,
			states: [],
			getatates:[],
		},
	},
});

// 初始化用户权限
const initUserAuth = () => {
	userAuth.value = userInfos.value.roles[0];
};


// 获取发布的作业
const onRadio = async () => {
	bind().getHomeWork().then(res => {
		state.tableData.data = res.data;
		for (let i = 0; i < state.tableData.data.length; i++) {
			state.tableData.param.states.push(res.data[i].hid)
			Session.set(res.data[i].hid, JSON.stringify(res.data[i].content))
		}
		//获取作业状态
		bind().getState(state.tableData.param.states).then(res => {
			 localStorage.setItem('states', JSON.stringify(res.data))
		})
		state.tableData.param.getatates=JSON.parse(localStorage.getItem("states") || '{}')
	})


};


//格式化后端返回来的时间
function getLocalTime(value: any) {
	let time = value.endtime[0] + '-' + value.endtime[1] + '-' + value.endtime[2] + ' ' + value.endtime[3] + ':' + value.endtime[4] + ':' + value.endtime[5]
	return time
}



//跳转到具体页面
const Jump = (scope: any) => {
	localStorage.setItem('hid', JSON.stringify(scope.row.hid))
	router.push("/fun/echartsMap")
}


// 页面加载时
onMounted(() => {
	initUserAuth()
	onRadio()
});


</script>




<!-- <template>
	<div class="croppers-container layout-pd">
		<el-card shadow="hover" header="cropper 图片裁剪">
			<el-alert
				title="感谢优秀的 `cropperjs`，项目地址：https://github.com/fengyuanchen/cropperjs"
				type="success"
				:closable="false"
				class="mb15"
			></el-alert>
			<div class="cropper-img-warp">
				<div class="mb15 mt15">
					<img class="cropper-img" :src="state.cropperImg" />
				</div>
				<el-button type="primary" size="default" @click="onCropperDialogOpen">
					<el-icon>
						<ele-Crop />
					</el-icon>
					更换头像
				</el-button>
			</div>
		</el-card>
		<CropperDialog ref="cropperDialogRef" />
	</div>
</template>

<script setup lang="ts" name="funCropper">
import { defineAsyncComponent, ref, reactive } from 'vue';

// 引入组件
const CropperDialog = defineAsyncComponent(() => import('/@/components/cropper/index.vue'));

// 定义变量内容
const cropperDialogRef = ref();
const state = reactive({
	cropperImg: 'https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500',
});

// 打开裁剪弹窗
const onCropperDialogOpen = () => {
	cropperDialogRef.value.openDialog(state.cropperImg);
};
</script>

<style scoped lang="scss">
.croppers-container {
	.cropper-img-warp {
		text-align: center;
		.cropper-img {
			margin: auto;
			width: 150px;
			height: 150px;
			border-radius: 100%;
		}
	}
}
</style> -->
